package com.taptech.doufu.util.at;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.ui.activity.PersonalSendLetterActivity;

public class AtClickListen
{

	private Context context;

	public AtClickListen(Context context, EditText editText, TextView textView)
	{
		// TODO Auto-generated constructor stub
		this.context = context;
		initAt(editText, textView);

	}

	private void initAt(final EditText editText, TextView textView)
	{
		// TODO Auto-generated method stub
		textView.setVisibility(View.VISIBLE);
		textView.setText("@");
		if (textView.getVisibility() == View.VISIBLE)
		{
			textView.setOnClickListener(new OnClickListener()
			{

				@Override
				public void onClick(View arg0)
				{
					// TODO Auto-generated method stub

					statFriendsActivity(Constant.AT_CLICK);

				}
			});
			editText.addTextChangedListener(new TextWatcher()
			{

				@Override
				public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
				{
					// TODO Auto-generated method stub

				}

				@Override
				public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
				{
					// TODO Auto-generated method stub

				}

				@Override
				public void afterTextChanged(Editable arg0)
				{
					// TODO Auto-generated method stub
					if (editText.getText().toString().endsWith("@"))
					{
						statFriendsActivity(Constant.AT_WRITE);
					}

				}
			});
		}
	}

	protected void statFriendsActivity(int type)
	{
		// TODO Auto-generated method stub
		Intent intent = new Intent(this.context, PersonalSendLetterActivity.class);
		intent.putExtra("TYPE", "fromNewUgc");
		((Activity) context).startActivityForResult(intent,type);
		((Activity) context).overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_in_from_left_at);// 切换activity的动画，直接输入动画R资源
	}

}
